def ceil(n):
    n=float(n)
    x=n*10%10
    if(x>0):
        return int(n)+1
    else:
        return int(n)
t=[]
n=int(input())
r=int(input())
for i in range(n):
    t.append(int(input()))
t=sorted(t)
s=[[] for x in range(r)]
temp=0
sums=[0 for x in range(r)]
if n%2!=0:
    temp=t[-1]
    t.remove(t[-1])
    n-=1
for i in range(0,r):
    for j in range(1,ceil(n/r/2)+1):
        if(i*j>n):
            break
        s[i].append(t[i*j])
        s[i].append(t[n-i*j-1])
#print(s)
for i in range(len(s)):
    for j in s[i]:
        sums[i]=sums[i]*2+j
if temp!=0:
    sums[sums.index(min(sums))]=sums[sums.index(min(sums))]*2+temp
print(sum(sums))